//
//  AYMWeatherView.m
//  QuickCure
//
//  Created by 徐绩 on 16/5/4.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "AYMWeatherView.h"

@implementation AYMWeatherView

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
    
        [self setupUI];
    }
    return self;
}

-(void)setupUI{

    self.backgroundColor = [UIColor colorWithRed:185/255.0 green:235/255.0 blue:216/255.0 alpha:1];

}

-(void)layoutSubviews{

    [super layoutSubviews];
    
    //分隔线
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:lineView];
    
    [lineView makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.equalTo(self.frame.size.height - 20);
        make.width.equalTo(1);
        make.center.equalTo(self);
        
    }];
    
    //天气图片
    UIImageView *weatherImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yin"]];
    [self addSubview:weatherImage];
    
    [weatherImage makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.equalTo(15);
        make.centerY.equalTo(self);
    }];
    
//    UILabel *weatherLabel = [[UILabel alloc]init];
//    [self addSubview:weatherImage];
    
    // 天气label
    UILabel *weatherLabel = [self addChildLabel:@"多云"];
    
    
    [weatherLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self);
        
        make.leading.equalTo(self).offset(65);
        
    }];
    
    
    
    // 地区
    UILabel *areaLabel = [self addChildLabel:@"上海"];
    areaLabel.userInteractionEnabled = YES;
    
    //点击手势
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didAreaLabelClick:)];
    
    [areaLabel addGestureRecognizer:tapGes];
    
    
    //约束
    [areaLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self);
        
        make.trailing.equalTo(lineView.leading).offset(-10);
        
    }];
    
    //下滑线
    UIView *areaLineView = [[UIView alloc] init];
    areaLineView.backgroundColor = random(80, 201, 197, 255);
    
    [self addSubview:areaLineView];
    
    [areaLineView makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(1);
        make.width.equalTo(areaLabel.width);
        make.top.equalTo(areaLabel.bottom);
        make.leading.equalTo(areaLabel.leading);
    }];
    
    
    
    // 温度
    UILabel *temperatureLabel = [self addChildLabel:@"温度"];
    
    [temperatureLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self).offset(-12);
        make.leading.equalTo(lineView.trailing).offset(30);
        
    }];
    
    //时间
    UILabel *timeLabel = [self addChildLabel:@"2016年05月05日"];
    
    [timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self).offset(12);
        make.leading.equalTo(lineView.trailing).offset(30);
        
    }];
    
    
    //温度显示
    UILabel *showTemperatureLabel = [self addChildLabel:@"27 ~ 26度"];
    
    [showTemperatureLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(temperatureLabel);
        
        make.trailing.equalTo(timeLabel.trailing);
    }];
    
}

#pragma mark - 添加天气label
- (UILabel *)addChildLabel:(NSString *)labelText{
    
    UILabel *label = [[UILabel alloc] init];
    
    label.text = labelText;
    
    label.textColor = random(80, 201, 197, 255);
    
    label.font = [UIFont systemFontOfSize:homeFont];
    
    [self addSubview:label];
    
    return label;
}

#pragma mark - 地区label点击事件
- (void)didAreaLabelClick: (UITapGestureRecognizer *) tapGes{
    
    
    
    Log(@"地区按钮点击");
    
    
}


@end
